﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace MyBehaviorTree
{
    public enum State
    {
       INVALID,SUSCCESS,RUNNING,FAILURE,APORTED
    }
    public class Behavior
    {
        public State state = State.INVALID;
        public BlackBoard blackBoard;

        public Behavior() { }
        public virtual void start() { }
        public virtual State update() { return state; }
        public virtual void end() { }

        public bool isEnd()
        {
            return state == State.SUSCCESS || state == State.FAILURE;
        }

        public State run()
        {
            if (state != State.RUNNING) start();
            state = update();
            if (state != State.RUNNING) end();
            return state;
        }

        public void reset()
        {
            state = State.INVALID;
        }

        public void abort()
        {
            end();
            state = State.APORTED;
        }
    }
}
